<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/css/layui.css">
    <link rel="stylesheet" href="/css/admin/index.css">
</head>
<body>
<div class="main">
{{include './header.html'}}
    <div class="content-box">
        <form action="" method="post" class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-block">
                    <input type="text" name="title" id="title" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">来源</label>
                <div class="layui-input-block">
                    <input type="text" id="author" name="origin" required  lay-verify="required" placeholder="请输入来源" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-block">
                    <select name="type" lay-verify="required" id="newstype">
                        <option value=""></option>
                        <option value="1">白</option>
                        <option value="2">黑</option>
                        <option value="3">JK</option>
                        <option value="4">幽默段子</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item" id="thimgbox">
                <label class="layui-form-label">缩略图</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" placeholder="上传缩略图" id="thinput" required  lay-verify="required">
                    <input name="token" type="hidden" value="" id="token">
                    <input name="key" type="hidden" value="" id="thname">
                    <input name="file" type="file" id="thimage" class="thimage layui-input" />
                </div>
            </div>
            <div class="layui-form-item" style="display: none;">
                <div class="layui-input-block">
                    <div class="thimgshow">
                        <img src="" id="thimg" alt="" width="220" height="150">
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">文章简介</label>
                <div class="layui-input-block">
                    <textarea name="desc" id="shortcontent" placeholder="请输入内容" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <div id="editor"></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="button" id="submitBtn" class="layui-btn" value="立即提交">
                </div>
            </div>
        </form>
    </div>
</div>
{{include './footer.html'}}
<script src="/js/wangEditor.min.js"></script>
<script src="/js/plupload.full.min.js"></script>
<script src="/js/qiniu.js"></script>
<script src="/js/qiniuAdmin2.js"></script>
<script type="text/javascript">
    var E = window.wangEditor
    var editor = new E('#editor')
    // 或者 var editor = new E( document.getElementById('editor') )
    // 允许上传到七牛云存储
    editor.customConfig.qiniu = true

    editor.create()

    // 初始化七牛上传
    uploadInit()

    $('#thimgbox').click(function(){
        $(this).addClass('current')
    })
    layui.use('form', function(){
        var element = layui.element;
    })

    layui.use('element', function(){
        var element = layui.element;
    });
    $('#submitBtn').click(function(){
        $.ajax({
            url:'/addNews',
            type:'post',
            data:JSON.stringify({
                title : $('#title').val(),
                origin : $('#author').val(),
                type : $('#newstype').val(),
                content : editor.txt.html(),
                thumb : $('#thimg').attr('src'),
                desc:$('#shortcontent').val()
            }),
            contentType: 'application/json',
            success : function(d){
                if(d.result=='ok'){
                    window.location.href = '/admin/newsList'
                }
            }
        })
    })
</script>
</body>
</html>